<?php
namespace Home\Controller;
use Think\Controller;
class TrainingController extends Controller {
 //  public function picturelist(){
  //      $pictureModel=M('picture');
  //      $data=$pictureModel->order('uid desc')->select();
  //      echo json_encode($data);
  //  }
  //  public function picturelist(){//当前用户所有晒图信息
 //     $id=$_GET['uid'];
  //      $pictureModel=M('picture');
 //       $data=$pictureModel->where("uid='$id'")->select();
 //       $this->assign('picturelist',$data);
 //       $this->display();
  //  }

    public function getAllTraining(){
        $trainingModel = M('training');
        $traininglist = $trainingModel->order("tid desc")->select();

        
        $this->assign('traininglist',$traininglist);
        $this->display();
    }
   // public function picturedetail(){
    //    $id["pid"]=I('get.pid');
   //     $data=M("picture")->where($id)->find();
   //     echo json_encode($data);
   // }
    public function getTrainingById(){//晒图详情
      $id=$_GET['tid'];
        $trainingModel=M('training');
       // $data=$pictureModel->where("pid='$id'")->find();
       // $this->assign('picdetail',$data);
     $data=$trainingModel->where("tid=$id")->find();
    //   $this->picturedetail=$data;
         $this->assign('trainingdetail',$data);
        //var_dump($data);

        $this->display();

    }
    public function edittraining($tid)
    {
       
    $trainingModel=M('training');
    $data=$trainingModel->where("tid=$tid")->find();
    $this->training=$data;
    $this->display();
    //var_dump($data);
    // echo json_encode($one);
   }
   // public function updatepicture(){
   //  $data=$_POST;
   //  $file=$_FILES;
   //  $pictureModel=M('picture');
   //  if($picturemodel->create()){
   //      if ($picturemodel->save()) {
   //          $this->success('修改成功','picturelist');
   //      }else{
   //          $this->error('修改失败');
   //      }
   //  }

   //  }
public function updatetraining(){

            $data=$_POST;
           // $file=$_FILES;
            $tid=$data['tid'];
            //dump($data);
           // dump($file);
                    
            $trainingModel = M('training'); // 实例化User模型
            // 要修改的数据对象属性赋值
            $trainingModel->create();   // 根据表单提交的POST数据创建数据对象
            //dump($data);
        $result=$trainingModel->where("tid=$tid")->save($data);

        // if($file['ppic']['size']==0) {
        //     //没有修改头像
        //     $result=$pictureModel->where("pid=$pid")->save($data);
  
        // }else{
        //     //修改头像
        //     $upload = new \Think\Upload();// 实例化上传类
        //     $upload->maxSize  = 3145728 ;// 设置附件上传大小
        //     $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        //     $upload->rootPath  =  './';
        //     $upload->savePath =  'Public/Uploads/picture/';// 设置附件上传目录
        //     $upload->autoSub = false;
        //     $upload->saveName = date("YmdHis").rand(100,999);//定义名字
        //     $info = $upload->upload();
    
        //     if(!$info) {// 上传错误提示错误信息
        //             $this->error($upload->getError());
        //      }else{// 上传成功 获取上传文件信息
        //          //保存表单数据 包括附件数据
        //         $data['ppic']= $info['ppic']['savename']; 
        //         $result=$pictureModel->where("pid=$pid")->save($data);
        //             if ($data['oldpic']!='nopic.jpg') {
        //             $oldpicPath='Public/Uploads/picture/'.$data['oldpic'];
        //             unlink($oldpicPath);
        //                 }
        //             }
        //     }
        if($result){
             $this->success('修改成功！','getAllTraining');
             }
            else{
                $this->error('修改失败！');
                }
    }

    public function deltraining( )
    {

       // $id=I('id');
        $id=$_GET['tid'];
        $trainingModel = M('training');//实例化news对象
        if($trainingModel->delete($id)) {
            $this->success('删除成功');
            //echo json_encode('1');
        }
        else {
           $this->error('删除失败');
          
            //echo json_encode('0');
        }
    }

    





  
}